/*
 * @Author: your name
 * @Date: 2023-09-30 21:03:58
 * @LastEditTime: 2023-11-17 16:34:14
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Angle\User\OperationSystem\system.h
 */
#ifndef _SYSTEM_EVENT_H_
#define _SYSTEM_EVENT_H_

#include "cmsis_os.h"

typedef struct __SystemStructdef
{
    /* 系统各类事件使用到的队列 */
    struct _SystemEvent{
        QueueHandle_t  UAV_UartRxQueue;
        QueueHandle_t  UAV_UartTxQueue;
        QueueHandle_t  Flow_UartRxQueue;
        QueueHandle_t  VL53L1_EXTIQueue;
        QueueHandle_t  VL53L1_TimerQueue;
        QueueHandle_t  IMU_Sensor_EXTIQueue;
        QueueHandle_t  Magnetometer_EXTIQueue;
    }SystemEvent;

    /* 用户队列 */
    struct {
        QueueHandle_t   UAV_SendDataQueue;
        QueueHandle_t   ImuDataQueue;
        QueueHandle_t   MagDataQueue;
        QueueHandle_t   AngleDataQueue;
    }UserQueues;

    /* 用户任务 */
    struct 
    {
        TaskHandle_t SensorTask;
        TaskHandle_t SendDataTask;
        TaskHandle_t ServoControlTask;
        TaskHandle_t AttitudeCalTask;
    }UserTasks;

    /* 用户信号量 */
    struct{
        SemaphoreHandle_t SendDataSem;
        SemaphoreHandle_t AttitudeCalSem;
    }UserSems;

    /* 传感器相关事件队列集 */
    QueueSetHandle_t SensorEventsSet;
}SystemStructdef;

typedef enum __EventTypeEnumdef
{
    NoneEvent,
    RecieveIdleEvent,
    RecieveCpltEvent,
    RecieveErrorEvent,
    TransmitCpltEvent,
    TimerElapsedEvent,
    EXTI_Event
}EventTypeEnumdef;

typedef struct __EventStructdef
{
    EventTypeEnumdef    eventType;      // 事件类型
    uint16_t            dataLen;        // 数据包长度，如果是接收事件，就会使用到这个数据
    uint64_t            eventTime;      // 时间发生的时间戳
}EventStructdef;


void SensorTaskFunc(void *argument);
void SendDataTaskFunc(void *argument);
void ServoControlTaskFunc(void *argument);
void System_Init(void);
void AttitudeCalFunc(void *argument);
uint8_t SendSensor1Data(void);
uint8_t SendStatusData(void);

extern SystemStructdef System;

#endif  /* _SYSTEM_EVENT_H_ */
